﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>SetKeyDelay - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The SetKeyDelay function sets the delay that will occur after each keystroke sent by the Send and ControlSend functions." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>SetKeyDelay</h1>

<p>Sets the delay that will occur after each keystroke sent by <a href="Send.htm">Send</a> and <a href="ControlSend.htm">ControlSend</a>.</p>

<pre class="Syntax"><span class="func">SetKeyDelay</span> <span class="optional">Delay, PressDuration, "Play"</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Delay</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>Time in milliseconds. Use -1 for no delay at all and 0 for the smallest possible delay (however, if the <em>Play</em> parameter is present, both 0 and -1 produce no delay). Leave this parameter blank to retain the current <em>Delay</em>.</p>
    <p>If SetKeyDelay is never used by a script, the default <em>Delay</em> for the tradional SendEvent mode is 10. For <a href="Send.htm#SendPlayDetail">SendPlay mode</a>, the default <em>Delay</em> is -1. The default <em>PressDuration</em> (below) is -1 for both modes.</p>
  </dd>

  <dt id="dur">PressDuration</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>Certain games and other specialized applications may require a delay inside each keystroke; that is, after the press of the key but before its release.</p>
    <p>Use -1 for no delay at all (default) and 0 for the smallest possible delay (however, if the <em>Play</em> parameter is present, both 0 and -1 produce no delay). Omit this parameter to leave the current <em>PressDuration</em> unchanged.</p>
    <p class="note"><strong>Note</strong>: <em>PressDuration</em> also produces a delay after any change to the modifier key state (<kbd>Ctrl</kbd>, <kbd>Alt</kbd>, <kbd>Shift</kbd>, and <kbd>Win</kbd>) needed to support the keys being sent.</p>
  </dd>

  <dt>Play</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The word <em>Play</em> applies the above settings to the <a href="Send.htm#SendPlayDetail">SendPlay mode</a> rather than the traditional SendEvent mode. If a script never uses this parameter, the delay is always -1/-1 for SendPlay.</p>
  </dd>

</dl>

<h2 id="Remarks">备注</h2>
<p class="note"><strong>Note:</strong> SetKeyDelay is not obeyed by <a href="Send.htm#SendInputDetail">SendInput</a>; there is no delay between keystrokes in that mode. This same is true for <a href="Send.htm">Send</a> when <a href="SendMode.htm">SendMode Input</a> is in effect.</p>
<p>A short delay (sleep) is done automatically after every keystroke sent by <a href="Send.htm">Send</a> or <a href="ControlSend.htm">ControlSend</a>. This is done to improve the reliability of scripts because a window sometimes can't keep up with a rapid flood of keystrokes.</p>
<p>During the delay (sleep), the current thread is made <a href="../misc/Threads.htm#Interrupt">uninterruptible</a>.</p>
<p>Due to the granularity of the OS's time-keeping system, delays might be rounded up to the nearest multiple of 10 or 15.</p>
<p>For Send/SendEvent mode, a delay of 0 internally executes a Sleep(0), which yields the remainder of the script's timeslice to any other process that may need it. If there is none, Sleep(0) will not sleep at all. By contrast, a delay of -1 will never sleep.  For better reliability, 0 is recommended as an alternative to -1.</p>
<p>When the delay is set to -1, a script's process-priority becomes an important factor in how fast it can send keystrokes when using the traditional <a href="SendMode.htm">SendEvent mode</a>. To raise a script's priority, use <code><a href="ProcessSetPriority.htm">ProcessSetPriority</a> "High"</code>. Although this typically causes keystrokes to be sent faster than the <a href="WinActivate.htm">active window</a> can process them, the system automatically buffers them. Buffered keystrokes continue to arrive in the target window after the <a href="Send.htm">Send</a> function completes (even if the window is no longer active). This is usually harmless because any subsequent keystrokes sent to the same window get queued up behind the ones already in the buffer.</p>
<p>The built-in variable <strong>A_KeyDelay</strong> contains the current setting of <em>Delay</em> for Send/SendEvent mode.  <strong>A_KeyDuration</strong> contains the setting for <em>PressDuration</em>, while <strong>A_KeyDelayPlay</strong> and <strong>A_KeyDurationPlay</strong> contain the settings for <a href="Send.htm#SendPlayDetail">SendPlay</a>.</p>
<p>每个新运行的<a href="../misc/Threads.htm">线程</a>(如 <a href="../Hotkeys.htm">热键</a>, <a href="../objects/Menu.htm">自定义菜单项</a>或<a href="SetTimer.htm">定时</a>子程序) 都会以此函数的默认设置开始. 这个默认设置可以通过在<a href="../Scripts.htm#auto">脚本启动</a>中使用此函数来改变.</p>
<h2 id="Related">相关</h2>
<p><a href="Send.htm">Send</a>, <a href="ControlSend.htm">ControlSend</a>, <a href="SendMode.htm">SendMode</a>, <a href="SetMouseDelay.htm">SetMouseDelay</a>, <a href="SetControlDelay.htm">SetControlDelay</a>, <a href="SetWinDelay.htm">SetWinDelay</a>, <a href="Click.htm">Click</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>SetKeyDelay 0</pre>
</div>

</body>
</html>